package mobileann.mafamily.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import com.mobileann.mafamily.R;
import com.mofind.android.base.L;
import com.mofind.android.net.HttpUtils;
import com.mofind.android.net.JSONParser;
import mobileann.mafamily.act.main.FS;
import mobileann.mafamily.db.model.ClickModuleModel;
import mobileann.mafamily.db.provider.ClickModuleProvider;
import mobileann.mafamily.entity.DialyTaskEntity;
import mobileann.mafamily.entity.IntegralLevelEntity;
import mobileann.mafamily.entity.MedalEntity;
import mobileann.mafamily.entity.CoinLogEntity;
import mobileann.mafamily.entity.MemberInfoEntity;
import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MyTaskUtils {
	public static final int GET_INFO_OK = 11;
	public static final int GET_INFO_FAIL = 12;
	public static final int LOGIN_OK = 413;
	public static final int LOGIN_ERROR = 414;
	private static MyTaskUtils instance;
	private static final String DisposableTag = "IntegralDisposable";
	private static final String IntegralTag = "integral";
	private static final String MedalTag = "IntegralMedal";
	private static final String CoinLogTag = "IntegralCoinLog";
	private String TAG = "MyTaskUtils";

	public static synchronized MyTaskUtils getInstance() {
		if (instance == null) {
			instance = new MyTaskUtils();
		}
		return instance;
	}

	/**
	 * 获取加密的json数据
	 * 
	 * @param c
	 * @param uid
	 * @param clickMap
	 *            点击模块的值与对应的点击的次数,从数据库中获得
	 * @return 加密的json数据
	 *         {"time":1423292815,"uid":123,"imei":"352910051163586","uuid":
	 *         "ffffffff-e8ac-fd4b-ffff-ffffcc68633a"
	 *         ,"1":2,"2":1,"3":1,"5":1,"6":1,"10":
	 *         3,"12":1,"18":"qijian"}，用户又后继有了操作如查看app使用详情
	 *         ，那么上面的记录中"1":2就改为"1":3，即{"time"
	 *         :1423292815,"uid":123,"imei":"352910051163586"
	 *         ,"uuid":"ffffffff-e8ac-fd4b-ffff-ffffcc68633a"
	 *         ,"1":3,"2":1,"3":1,"5":1,"6":1,"10":3,"12":1,"18":"qijian"}
	 */
	public String getJsonDatas(Context c, String uid) {
		Map<String, String> map = new HashMap<String, String>();
		ClickModuleModel model = new ClickModuleModel(c);
		map.put("time", System.currentTimeMillis() / 1000 + "");
		// map.put("uid", SPUtils.getUID2() );
		map.put("uid", SPUtils.getMySelf(SPUtils.MYUID));
		map.put("imei", PhoneInfoUtils.getIMEI(c));
		if (model.getClickTimes(ClickModuleProvider.APPDETAILS_TIMES, uid) != 0) {
			map.put("1",
					model.getClickTimes(ClickModuleProvider.APPDETAILS_TIMES,
							uid) + "");
		}
		if (model.getClickTimes(ClickModuleProvider.LOCATION_TIMES, uid) != 0) {
			map.put("2",
					model.getClickTimes(ClickModuleProvider.LOCATION_TIMES, uid)
					+ "");
		}
		if (model.getClickTimes(ClickModuleProvider.TRACK_TIMES, uid) != 0) {
			map.put("3",
					model.getClickTimes(ClickModuleProvider.TRACK_TIMES, uid)
					+ "");
		}
		if (model.getClickTimes(ClickModuleProvider.CHAT_TIMES, uid) != 0) {
			map.put("4",
					model.getClickTimes(ClickModuleProvider.CHAT_TIMES, uid)
					+ "");
		}
		if (model.getClickTimes(ClickModuleProvider.LOCK_TIMES, uid) != 0) {
			map.put("5",
					model.getClickTimes(ClickModuleProvider.LOCK_TIMES, uid)
					+ "");
		}
		if (model.getClickTimes(ClickModuleProvider.ADDLOCK_TIMES, uid) != 0) {
			map.put("6",
					model.getClickTimes(ClickModuleProvider.ADDLOCK_TIMES, uid)
					+ "");
		}
		if (model.getClickTimes(ClickModuleProvider.ELE_TIMES, uid) != 0) {
			map.put("7",
					model.getClickTimes(ClickModuleProvider.ELE_TIMES, uid)
					+ "");
		}
		if (model.getClickTimes(ClickModuleProvider.UPDATEHEADPIC_TIMES, uid) != 0) {
			map.put("8",
					model.getClickTimes(
							ClickModuleProvider.UPDATEHEADPIC_TIMES, uid) + "");
		}
		if (model.getClickTimes(ClickModuleProvider.UPDATENICKNAME_TIMES, uid) != 0) {
			map.put("9",
					model.getClickTimes(
							ClickModuleProvider.UPDATENICKNAME_TIMES, uid) + "");
		}
		if (model.getClickTimes(ClickModuleProvider.SHAREQQ_TIMES, uid) != 0) {
			map.put("10",
					model.getClickTimes(ClickModuleProvider.SHAREQQ_TIMES, uid)
					+ "");
		}
		if (model.getClickTimes(ClickModuleProvider.SHAREMICRO_TIMES, uid) != 0) {
			map.put("11",
					model.getClickTimes(ClickModuleProvider.SHAREMICRO_TIMES,
							uid) + "");
		}
		if (model.getClickTimes(ClickModuleProvider.SHAREQZONE_TIMES, uid) != 0) {
			map.put("12",
					model.getClickTimes(ClickModuleProvider.SHAREQZONE_TIMES,
							uid) + "");
		}
		if (model.getClickTimes(ClickModuleProvider.SHAREFRIENDS_TIMES, uid) != 0) {
			map.put("13",
					model.getClickTimes(ClickModuleProvider.SHAREFRIENDS_TIMES,
							uid) + "");
		}
		if (model.getClickTimes(ClickModuleProvider.SHAREWEB_TIMES, uid) != 0) {
			map.put("14",
					model.getClickTimes(ClickModuleProvider.SHAREWEB_TIMES, uid)
					+ "");
		}
		if (model.getClickTimes(ClickModuleProvider.SHARESHORTMSG_TIMES, uid) != 0) {
			map.put("15",
					model.getClickTimes(
							ClickModuleProvider.SHARESHORTMSG_TIMES, uid) + "");
		}
		if (model.getClickTimes(ClickModuleProvider.LAUNCH_TIMES, uid) != 0) {
			map.put("16",
					model.getClickTimes(ClickModuleProvider.LAUNCH_TIMES, uid)
					+ "");
		}
		if (!TextUtils.isEmpty(model.getAddTel(uid))) {
			map.put("17", model.getAddTel(uid));
		}
		if (!SPUtils.getVersionChannel(SPUtils.getUID()).equals(
				PhoneInfoUtils.getVersionChannel(c))) {// 渠道码改变了
			map.put("18", PhoneInfoUtils.getVersionChannel(c));
			SPUtils.setVersionChannel(SPUtils.getUID(),
					PhoneInfoUtils.getVersionChannel(c));
		}
		String data = map2json(map);
		// return TripleDESUtil.CBCEncode(SPUtils.getUID2(), SPUtils.getIRAD(),
		// data);
		return TripleDESUtil.CBCEncode(SPUtils.getMySelf(SPUtils.MYUID),
				SPUtils.getMySelf(SPUtils.MYIRAD), data);
	}

	/**
	 * Map集合转换为Json
	 * 
	 * @param map
	 */
	public synchronized String map2json(Map<String, String> map) {
		StringBuilder json = new StringBuilder();
		json.append("{");
		if (map != null && map.size() > 0) {
			for (Object key : map.keySet()) {
				json.append("\"" + key + "\"");
				json.append(":");
				json.append("\"" + map.get(key) + "\"");
				json.append(",");
			}
			json.setCharAt(json.length() - 1, '}');
		} else {
			json.append("}");
		}
		return json.toString();
	}
	public synchronized String map2json2(Map<String, String> map) {
		StringBuilder json = new StringBuilder();
		json.append("{");
		if (map != null && map.size() > 0) {
			for (Object key : map.keySet()) {
				json.append("\"" + key + "\"");
				json.append(":");
				json.append(map.get(key));
				json.append(",");
			}
			json.setCharAt(json.length() - 1, '}');
		} else {
			json.append("}");
		}
		return json.toString();
	}

	public String getQueryString(String tag) {
		// String queryStr = SPUtils.getUID2() + "_" + SPUtils.getIRAD() + "_"
		// + tag;
		String queryStr = SPUtils.getMySelf(SPUtils.MYUID) + "_"
				+ SPUtils.getMySelf(SPUtils.MYIRAD) + "_" + tag;
		return queryStr;
	}

	/**
	 * 用户积分等级信息
	 * 成功：{"coin":200,"level":2,"rank":"\u9887\u5177\u540d\u6c14","points":50,
	 * "next_points":10,"medal":{"1":2,"2":0,"3":0},"disposable":[10,12]}
	 */
	public void IntegralLevelInfo(final Handler mHandler) {
		final IntegralLevelEntity entity = new IntegralLevelEntity();
		HttpUtils.startHttpGet(URLUtils.URL_TASK_GET
				+ getQueryString(IntegralTag), new HttpUtils.HttpResultCallback() {
			@Override
			public void result(String url, boolean isResult, String jsonStr) {
				if (isResult) {
					try {
						// String json = TripleDESUtil.getJsonObjStr(
						// SPUtils.getUID2(), SPUtils.getIRAD(), jsonStr);
						String json = TripleDESUtil.getJsonObjStr(
								SPUtils.getMySelf(SPUtils.MYUID),
								SPUtils.getMySelf(SPUtils.MYIRAD), jsonStr);
						JSONObject jo = JSONParser.getJSONObject(json);
						int coin = JSONParser.getInt(jo, "coin");
						int level = JSONParser.getInt(jo, "level");
						String rank = JSONParser.getString(jo, "rank");
						int points = JSONParser.getInt(jo, "points");
						int next_points = JSONParser.getInt(jo, "next_points");
						JSONObject medal = JSONParser
								.getJSONObject(jo, "medal");
						ArrayList<MedalEntity> medalList = new ArrayList<MedalEntity>();
						for (int i = 1; i < 5; i++) {
							MedalEntity med = new MedalEntity();
							int num = JSONParser.getInt(medal, i + "");
							med.setMedalID(i);
							med.setMedalNum(num);
							med.setMedalStatus(num);
							med.setHasAward(false);
							medalList.add(med);
						}
						JSONObject disposables = JSONParser.getJSONObject(jo,
								"disposable");
						List<Integer> disposable = new ArrayList<Integer>();
						if (disposables != null) {
							Iterator<String> keyIter = disposables.keys();
							String key;
							while (keyIter.hasNext()) {
								key = (String) keyIter.next();
								disposable.add(Integer.parseInt(key));
							}
						}
						JSONObject notreceive = JSONParser.getJSONObject(jo,
								"award");
						JSONObject notreceive_coins = JSONParser.getJSONObject(
								notreceive, "coin");
						Map<String, Integer> coins = new HashMap<String, Integer>();
						Iterator<String> keyIter = notreceive_coins.keys();
						String key;
						Object value;
						while (keyIter.hasNext()) {
							key = (String) keyIter.next();
							value = notreceive_coins.get(key);
							coins.put(key, Integer.parseInt(value + ""));
						}
						JSONObject notreceive_medals = JSONParser
								.getJSONObject(notreceive, "medal");
						Map<String, Integer> medals = new HashMap<String, Integer>();
						Iterator<String> keyIterator = notreceive_medals.keys();
						String key2;
						Object value2;
						while (keyIterator.hasNext()) {
							key2 = (String) keyIterator.next();
							value2 = notreceive_medals.get(key2);
							medals.put(key2, Integer.parseInt(value2 + ""));
						}
						for (int i = 1; i < 5; i++) {
							if (medalList != null && medalList.size() > 0
									&& medals.containsKey(i + "")) {
								if (medals.get(i + "") > 0) {
									medalList.get(i - 1).setHasAward(true);
								}
							}
						}
						JSONObject daily = JSONParser
								.getJSONObject(jo, "daily");
						int date = JSONParser.getInt(daily, "date");
						DialyTaskEntity dialyTaskEntity = new DialyTaskEntity();
						Map<String, Integer> dialytasks = new HashMap<String, Integer>();
						Iterator<String> iterator = daily.keys();
						String key3;
						Object value3;
						while (iterator.hasNext()) {
							key3 = (String) iterator.next();
							value3 = daily.get(key3);
							if (!key3.equals("date")) {
								dialytasks.put(key3,
										Integer.parseInt(value3 + ""));
							}
						}
						dialyTaskEntity.setDate(date);
						dialyTaskEntity.setCode(dialytasks);
						int addTimes = JSONParser.getInt(jo, "add_times");
						entity.setAddTimes(addTimes);
						entity.setCoin(coin);
						entity.setLevel(level);
						entity.setRank(rank);
						entity.setPoints(points);
						entity.setNext_points(next_points);
						entity.setMedals(medalList);
						entity.setDisposable(disposable);
						entity.setNotreceive_coins(coins);
						entity.setNotreceive_medals(medals);
						entity.setDialyTaskEntity(dialyTaskEntity);
						//new
						int is_commend=JSONParser.getInt(jo, "is_commend");
						entity.setIs_commend(is_commend);
						//
						LevelEntityUtils.getInstance().setLevelEntity(entity);
						if (!LevelEntityUtils.getInstance().hasMedalAward()) {
							SPUtils.setMedalPagePop(false);
						}
						if (mHandler != null) {
							mHandler.obtainMessage(GET_INFO_OK).sendToTarget();
						}
					} catch (Exception e) {
						L.e("maf", "error--", e);
					}
				}else{
					if (mHandler != null) {
						mHandler.obtainMessage(GET_INFO_FAIL).sendToTarget();
					}
				}
			}
		});
	}

	public void isFinishedOnceTask() {
		HttpUtils.startHttpGet(URLUtils.URL_TASK_GET
				+ getQueryString(DisposableTag), new HttpUtils.HttpResultCallback() {
			@Override
			public void result(String url, boolean isResult, String jsonStr) {
				// TODO Auto-generated method stub
				if (isResult) {
					try {
						// L.i("JSON", jsonStr + "");
					} catch (Exception e) {
						L.e("maf", "error--", e);
					}
				}
			}
		});
	}

	public void AwardInfo(final Handler handler, String code, final int codeTag) {
		HttpUtils.startHttpGet(
				URLUtils.URL_TASK_GET + getQueryString(MedalTag),
				new HttpUtils.HttpResultCallback() {
					@Override
					public void result(String url, boolean isResult,
							String jsonStr) {
						// TODO Auto-generated method stub
						if (isResult) {
							try {
								// String result = TripleDESUtil.getJsonObjStr(
								// SPUtils.getUID2(), SPUtils.getIRAD(),
								// jsonStr);
								String result = TripleDESUtil.getJsonObjStr(
										SPUtils.getMySelf(SPUtils.MYUID),
										SPUtils.getMySelf(SPUtils.MYIRAD),
										jsonStr);
								JSONObject medals = JSONParser
										.getJSONObject(result);
								for (int i = 1; i < 5; i++) {
									int num = JSONParser.getInt(medals, i + "");
									LevelEntityUtils.getInstance()
									.getLevelEntity().getMedals()
									.get(i).setMedalNum(num);
								}
								LevelEntityUtils.getInstance().getLevelEntity()
								.getMedals().get(codeTag)
								.setHasAward(false);
								if (handler != null)
									handler.obtainMessage(GET_INFO_OK)
									.sendToTarget();
							} catch (Exception e) {
								L.e("maf", "error--", e);
							}
						}
					}
				});
	}

	public void loginInfo(final String count, final String pwd) {
		HttpUtils.startHttpGet(URLUtils.URL_TASK_GET + count + "_" + pwd
				+ "_login", new HttpUtils.HttpResultCallback() {
			@Override
			public void result(String url, boolean isResult, String jsonStr) {
				if (isResult) {
					try {
						String result = TripleDESUtil.getJsonObjStr(count, pwd,
								jsonStr);
						JSONObject jo = JSONParser.getJSONObject(result);
						String uid2 = JSONParser.getString(jo, "uid");
						//			SPUtils.setUID2(uid2);
						String fid2 = JSONParser.getString(jo, "fid");
						//			SPUtils.setFID2(fid2);
						String urad = JSONParser.getString(jo, "urad");
						//			SPUtils.setURAD(urad);
						String frad = JSONParser.getString(jo, "frad");
						//			SPUtils.setFRAD(frad);
						String irad = JSONParser.getString(jo, "irad");
						//			SPUtils.setIRAD(irad);
					} catch (Exception e) {
						L.e("maf", "error--", e);
					}
				}
			}
		});
	}

	public void loginInfo2(final String count, final String pwd,
			final Handler handler) {
		if(count==null||pwd==null){
			if(handler!=null)
				handler.obtainMessage(LOGIN_ERROR).sendToTarget();
		}else{
			HttpUtils.startHttpGet(URLUtils.URL_TASK_GET + count + "_" + pwd
					+ "_login", new HttpUtils.HttpResultCallback() {
				@Override
				public void result(String url, boolean isResult, String jsonStr) {
					if (isResult) {
						try {
							String result = TripleDESUtil.getJsonObjStr(count, pwd,
									jsonStr);
							JSONObject jo = JSONParser.getJSONObject(result);
							String status=JSONParser.getString(jo, "status");
							if(status==null){
								String uid2 = JSONParser.getString(jo, "uid");
								//			SPUtils.setUID2(uid2);
								String fid2 = JSONParser.getString(jo, "fid");
								//			SPUtils.setFID2(fid2);
								String urad = JSONParser.getString(jo, "urad");
								//			SPUtils.setURAD(urad);
								String frad = JSONParser.getString(jo, "frad");
								//			SPUtils.setFRAD(frad);
								String irad = JSONParser.getString(jo, "irad");
								//			SPUtils.setIRAD(irad);
								MemberInfoEntity entity = new MemberInfoEntity();
								entity.setUid(uid2);
								entity.setUrad(urad);
								entity.setFrad(frad);
								entity.setFid(fid2);
								entity.setIrad(irad);
								SPUtils.saveMySelf(entity);
								// L.i(TAG+"rad",
								// result+"::"+uid2+"::"+fid2+"::"+urad+"::"+frad+"::"+irad);
								if(handler!=null)
									handler.obtainMessage(LOGIN_OK).sendToTarget();
							}else{
								if(handler!=null)
									handler.obtainMessage(LOGIN_ERROR).sendToTarget();
							}
						} catch (Exception e) {
							L.e("maf", "error--", e);
						}
					}
				}
			});
		}
	}

	/**
	 * 领取奖励
	 * 
	 * @param c
	 * @param uid
	 * @param code
	 *            领取的是金币还是勋章
	 * @param codeTag
	 *            领取的任务操作码
	 * @return
	 */
	public String getAward3DES(Context c, String uid, String code, int codeTag) {
		long time = System.currentTimeMillis() / 1000;
		String imei = PhoneInfoUtils.getIMEI(c);
		String data = "{\"time\":" + time + ",\"uid\":" + uid + ",\"imei\":\""
				+ imei + "\",\"" + code + "\":" + codeTag + "}";
		// return TripleDESUtil.CBCEncode(SPUtils.getUID2(), SPUtils.getIRAD(),
		// data);
		return TripleDESUtil.CBCEncode(SPUtils.getMySelf(SPUtils.MYUID),
				SPUtils.getMySelf(SPUtils.MYIRAD), data);
	}

	/*
	 * 积分体系中上传点击某功能的次数
	 */
	public void doClickMedule2Server(final Context c) {
		final ClickModuleModel meduleModel = new ClickModuleModel(c);
		HttpUtils.startHttpPost(URLUtils.URL_GROWTH_UPLOAD,
				URLUtils.getIntegralPara(c, SPUtils.getMySelf(SPUtils.MYUID)),
				new HttpUtils.HttpResultCallback() {
			@Override
			public void result(String url, boolean isResult,
					String jsonStr) {
				if (isResult) {
					// String result = TripleDESUtil.getJsonObjStr(
					// SPUtils.getUID2(), SPUtils.getIRAD(),
					// jsonStr);
					String result = TripleDESUtil.getJsonObjStr(
							SPUtils.getMySelf(SPUtils.MYUID),
							SPUtils.getMySelf(SPUtils.MYIRAD), jsonStr);
					JSONObject jo = JSONParser.getJSONObject(result);
					String status = JSONParser.getString(jo, "status");
					if (!TextUtils.isEmpty(status)) {
						if ("true".equals(status)) {
							meduleModel.deleteClickModuleTable();
							meduleModel.insertAction();
						} else {
							L.e(TAG, "上传数据失败");
						}
					} else {
						L.e(TAG, "ERROR");
					}
				}
			}
		});
	}

	/*
	 * 领取奖励
	 */
	public void doRecReward2Server(final Context c, final String code,
			final int codeTag, final ImageView view, final TextView tv,
			final Handler handler) {
		HttpUtils.startHttpPost(URLUtils.URL_GROWTH_UPLOAD, URLUtils
				.getAwardPara(c, SPUtils.getMySelf(SPUtils.MYUID), code,
						codeTag), new HttpUtils.HttpResultCallback() {
			@Override
			public void result(String url, boolean isResult, String jsonStr) {
				if (isResult) {
					try {
						// String result = TripleDESUtil.getJsonObjStr(
						// SPUtils.getUID2(), SPUtils.getIRAD(),
						// jsonStr);
						String result = TripleDESUtil.getJsonObjStr(
								SPUtils.getMySelf(SPUtils.MYUID),
								SPUtils.getMySelf(SPUtils.MYIRAD), jsonStr);
						// String test = "{\"status\":true}";
						JSONObject jo = JSONParser.getJSONObject(result);
						String status = JSONParser.getString(jo, "status");
						if (!TextUtils.isEmpty(status)) {
							if ("true".equals(status)) {
								Toast.makeText(c, "领取成功", Toast.LENGTH_SHORT)
								.show();
								if (view != null && tv != null) {
									doAnimation(view);
									if (codeTag == 16) {
										tv.setText("已签到");
									} else {
										tv.setText(c.getResources().getString(
												R.string.mytask_finished));
									}
									tv.setTextColor(c.getResources().getColor(
											R.color.black6));
									tv.setBackgroundResource(R.color.black10);
								}
								if (handler != null)
									IntegralLevelInfo(handler);
								// AwardInfo(handler,code,codeTag);
							} else {
								L.i(TAG + "J", status);
							}
						}
					} catch (Exception e) {
						L.e("maf", "error--", e);
					}

				}
			}
		});
	}

	/**
	 * 获取用户金币记录
	 */
	public void getCoinLog(final Handler handler) {
		HttpUtils.startHttpGet(URLUtils.URL_TASK_GET
				+ getQueryString(CoinLogTag), new HttpUtils.HttpResultCallback() {
			@Override
			public void result(String url, boolean isResult, String jsonStr) {
				// TODO Auto-generated method stub
				if (isResult) {
					try {
						// L.i(TAG, "Json::"+URLUtils.URL_TASK_GET
						// + getQueryString(CoinLogTag));
						// String result = TripleDESUtil.getJsonArrStr(
						// SPUtils.getUID2(), SPUtils.getIRAD(), jsonStr);
						String result = TripleDESUtil.getJsonArrStr(
								SPUtils.getMySelf(SPUtils.MYUID),
								SPUtils.getMySelf(SPUtils.MYIRAD), jsonStr);
						if (TextUtils.isEmpty(result)
								|| result.contains("false")) {
							Toast.makeText(FS.getInstance(), "数据加载失败，请稍后重试",
									Toast.LENGTH_SHORT).show();
						} else {
							JSONArray coinsLog = JSONParser
									.getJSONArray(result);
							int length = coinsLog.length();
							ArrayList<CoinLogEntity> CoinLogList = new ArrayList<CoinLogEntity>();
							for (int i = 0; i < length; i++) {
								JSONObject log = JSONParser.getJSONObject(
										coinsLog, i);
								int code = JSONParser.getInt(log, "code");
								int amount = JSONParser.getInt(log, "amount");
								String date = JSONParser.getString(log, "date");
								CoinLogEntity entity = new CoinLogEntity();
								entity.setCode(code);
								entity.setAmount(amount);
								entity.setDate(date);
								CoinLogList.add(entity);
							}
							handler.obtainMessage(GET_INFO_OK, CoinLogList)
							.sendToTarget();
							// JSONObject coinsLog = JSONParser
							// .getJSONObject(result);
							// ArrayList<CoinLogEntity> CoinLogList = new
							// ArrayList<CoinLogEntity>();
							// Iterator<String> keyIter = coinsLog.keys();
							// while (keyIter.hasNext()) {
							// String key = (String) keyIter.next();
							// JSONObject log = JSONParser.getJSONObject(
							// coinsLog, key);
							// int index = Integer.parseInt(key);
							// int code = JSONParser.getInt(log, "code");
							// int amount = JSONParser.getInt(log, "amount");
							// String date = JSONParser.getString(log, "date");
							// CoinLogEntity entity = new CoinLogEntity();
							// entity.setIndex(index);
							// entity.setCode(code);
							// entity.setAmount(amount);
							// entity.setDate(date);
							// CoinLogList.add(entity);
							// }
						}
					} catch (Exception e) {
						L.e("maf", "error--", e);
					}
				}
			}
		});
	}

	private void doAnimation(View view) {
		// 初始化 动画
		AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
		ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 2.0f, 1.0f,
				2.0f);
		// 动画集
		AnimationSet set = new AnimationSet(true);
		// set.addAnimation(translateAnimation);
		set.addAnimation(alphaAnimation);
		set.addAnimation(scaleAnimation);
		// 设置动画时间 (作用到每个动画)
		set.setDuration(1000);
		view.startAnimation(set);
	}

	public String getNowTime(long milliseconds) {
		Date now = new Date(milliseconds);
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");// 可以方便地修改日期格式
		String hehe = dateFormat.format(now);
		return hehe;
	}
}
